<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>BNF for AS2JavaParser.jcc</TITLE>
</HEAD>
<BODY>
<H1 ALIGN=CENTER>BNF for AS2JavaParser.jcc</H1>
<H2 ALIGN=CENTER>TOKENS</H2>
<TABLE>
 <!-- Token -->
 <TR>
  <TD>
   <PRE>
&lt;DEFAULT&gt; SKIP : {
" "
| "\t"
| "\n"
| "\r"
| &lt;"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")&gt;
| &lt;"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/"&gt;
}

   </PRE>
  </TD>
 </TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
// Note: i do not why, but vars must be defined before TK_BEGIN and END
</PRE>
  </TD>
 </TR>
 <!-- Token -->
 <TR>
  <TD>
   <PRE>
&lt;DEFAULT&gt; TOKEN : {
&lt;VAR: &lt;UP_LETTER&gt; (&lt;CHAR&gt;)*&gt;
}

   </PRE>
  </TD>
 </TR>
 <!-- Token -->
 <TR>
  <TD>
   <PRE>
&lt;DEFAULT&gt; TOKEN : {
&lt;TK_TRUE: "true"&gt;
| &lt;TK_FALSE: "false"&gt;
| &lt;TK_NOT: "not"&gt;
| &lt;TK_NEG: "~"&gt;
| &lt;TK_INTDIV: "div"&gt;
| &lt;TK_INTMOD: "mod"&gt;
| &lt;TK_BEGIN: "begin"&gt;
| &lt;TK_END: "end"&gt;
| &lt;TK_IMPORT: "import"&gt;
| &lt;TK_EXPORT: "export"&gt;
| &lt;TK_SCOPER: "::"&gt;
| &lt;TK_LABEL_AT: "@"&gt;
| &lt;NUMBER: ["0"-"9"] (["0"-"9"])* | (["0"-"9"])* "." (["0"-"9"])+ (&lt;EXPONENT&gt;)? | (["0"-"9"])+ &lt;EXPONENT&gt;&gt;
| &lt;EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+&gt;
| &lt;STRING: "\"" (~["\"","\\","\n","\r"] | "\\" (["n","t","b","r","f","\\","\'","\""] | ["0"-"7"] (["0"-"7"])? | ["0"-"3"] ["0"-"7"] ["0"-"7"]))* "\""&gt;
| &lt;ATOM: (&lt;LC_LETTER&gt; | "." &lt;CHAR&gt;) (&lt;CHAR&gt; | "." &lt;CHAR&gt;)*&gt;
| &lt;UNNAMEDVAR: "_" (&lt;CHAR&gt;)*&gt;
| &lt;CHAR: &lt;LETTER&gt; | &lt;DIGIT&gt; | "_"&gt;
| &lt;LETTER: &lt;LC_LETTER&gt; | &lt;UP_LETTER&gt;&gt;
| &lt;LC_LETTER: ["a"-"z"]&gt;
| &lt;UP_LETTER: ["A"-"Z"]&gt;
| &lt;DIGIT: ["0"-"9"]&gt;
}

   </PRE>
  </TD>
 </TR>
</TABLE>
<H2 ALIGN=CENTER>NON-TERMINALS</H2>
<TABLE>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* AgentSpeak Grammar */

/*   agent ::= bels goals plans

     returns true if achieved the end of file
     returns false if achieved a "{ end }" directive  
*/</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod1">agentBody</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( <A HREF="#prod2">directive</A> )* ( <A HREF="#prod3">belief</A> ( <A HREF="#prod2">directive</A> )* )* ( <A HREF="#prod4">initial_goal</A> ( <A HREF="#prod2">directive</A> )* )* ( <A HREF="#prod5">plan</A> ( <A HREF="#prod3">belief</A> )* ( <A HREF="#prod2">directive</A> )* )* &lt;EOF&gt;</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Directive 

   returns true if the directive is "{ end }", false otherwise
*/</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod2">directive</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>"{" ( &lt;TK_BEGIN&gt; <A HREF="#prod6">pred</A> "}" <A HREF="#prod1">agentBody</A> | &lt;TK_IMPORT&gt; <A HREF="#prod7">importive</A> "}" | &lt;TK_EXPORT&gt; <A HREF="#prod8">exportive</A> "}" | <A HREF="#prod6">pred</A> "}" )</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Beliefs & Rules */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod3">belief</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod9">literal</A> ( ":-" <A HREF="#prod10">log_expr</A> )? "."</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Initial goals */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod4">initial_goal</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>"!" <A HREF="#prod9">literal</A> "."</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Plan */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod5">plan</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;TK_LABEL_AT&gt; <A HREF="#prod6">pred</A> )? <A HREF="#prod11">trigger</A> ( ":" <A HREF="#prod10">log_expr</A> )? ( "&lt;-" <A HREF="#prod12">plan_body</A> )? "."</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Trigger */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod11">trigger</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( "+" | "-" ) ( ( "!" | "?" ) )? ( <A HREF="#prod9">literal</A> | <A HREF="#prod13">var</A> )</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Plan body */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod12">plan_body</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod14">body_formula</A> ( ";" <A HREF="#prod12">plan_body</A> )?</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod15">plan_term</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>"{" ( ( &lt;TK_LABEL_AT&gt; <A HREF="#prod6">pred</A> )? <A HREF="#prod11">trigger</A> ( ":" <A HREF="#prod10">log_expr</A> )? ( ( "&lt;-" | ";" ) )? )? ( <A HREF="#prod12">plan_body</A> )? "}"</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod14">body_formula</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( "!" | "!!" | "?" | "+" | ( "-" ( "+" )? ) )? <A HREF="#prod10">log_expr</A></TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Literal */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod9">literal</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( ( ( &lt;TK_NEG&gt; )? <A HREF="#prod6">pred</A> ) | &lt;TK_TRUE&gt; | &lt;TK_FALSE&gt; )</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Annotated Formulae */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod6">pred</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( ( <A HREF="#prod16">module</A> )? &lt;TK_SCOPER&gt; &lt;ATOM&gt; | &lt;ATOM&gt; | &lt;TK_BEGIN&gt; | &lt;TK_END&gt; ) ( "(" <A HREF="#prod17">terms</A> ")" )? ( <A HREF="#prod15">plan_term</A> )* ( <A HREF="#prod18">list</A> )?</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Import Directive */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod7">importive</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod16">module</A> ( "=" <A HREF="#prod19">string</A> )?</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod16">module</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>&lt;ATOM&gt;</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* Export Directive */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod8">exportive</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod20">exportive_term</A> ( "," <A HREF="#prod20">exportive_term</A> )*</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod20">exportive_term</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;ATOM&gt; | "?" ) ( "/" ( &lt;NUMBER&gt; | "?" ) )?</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* List of terms */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod17">terms</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod21">term</A> ( "," <A HREF="#prod21">term</A> )*</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod21">term</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( <A HREF="#prod18">list</A> | <A HREF="#prod15">plan_term</A> | <A HREF="#prod10">log_expr</A> )</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod18">list</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>"[" ( <A HREF="#prod22">term_in_list</A> ( "," <A HREF="#prod22">term_in_list</A> )* ( "|" ( &lt;VAR&gt; | &lt;UNNAMEDVAR&gt; | <A HREF="#prod18">list</A> ) )? )? "]"</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
// term_in_list is the same as term, but log_expr/plan_body must be enclosed by "("....")" to avoid problem with |
</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod22">term_in_list</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( <A HREF="#prod18">list</A> | <A HREF="#prod23">arithm_expr</A> | <A HREF="#prod19">string</A> | <A HREF="#prod15">plan_term</A> )</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* logical expression */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod10">log_expr</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod24">log_expr_trm</A> ( "|" <A HREF="#prod10">log_expr</A> )?</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod24">log_expr_trm</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod25">log_expr_factor</A> ( "&amp;" <A HREF="#prod24">log_expr_trm</A> )?</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod25">log_expr_factor</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;TK_NOT&gt; <A HREF="#prod25">log_expr_factor</A> | <A HREF="#prod26">rel_expr</A> )</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* relational expression 
   used in context, body and term
   
     <VAR>      [ <OPREL> <EXP> ]  --> this method returns the VarTerm
   | <LITERAL>  [ <OPREL> <EXP> ]  --> returns the Literal
   | <EXP>      [ <OPREL> <EXP> ]  --> returns the ExprTerm 
*/</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod26">rel_expr</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( <A HREF="#prod23">arithm_expr</A> | <A HREF="#prod19">string</A> ) ( ( "&lt;" | "&lt;=" | "&gt;" | "&gt;=" | "==" | "\\==" | "=" | "=.." ) ( <A HREF="#prod23">arithm_expr</A> | <A HREF="#prod19">string</A> | <A HREF="#prod18">list</A> | <A HREF="#prod15">plan_term</A> ) )?</TD>
</TR>
 <!-- Special token -->
 <TR>
  <TD>
<PRE>
/* arithmetic expression */</PRE>
  </TD>
 </TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod23">arithm_expr</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod27">arithm_expr_trm</A> ( ( "+" | "-" ) <A HREF="#prod23">arithm_expr</A> )?</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod27">arithm_expr_trm</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod28">arithm_expr_factor</A> ( ( "*" | "/" | &lt;TK_INTDIV&gt; | &lt;TK_INTMOD&gt; ) <A HREF="#prod27">arithm_expr_trm</A> )?</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod28">arithm_expr_factor</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod29">arithm_expr_simple</A> ( ( "**" ) <A HREF="#prod28">arithm_expr_factor</A> )?</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod29">arithm_expr_simple</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;NUMBER&gt; | "-" <A HREF="#prod29">arithm_expr_simple</A> | "(" <A HREF="#prod10">log_expr</A> ")" | <A HREF="#prod13">var</A> | <A HREF="#prod30">function</A> )</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod30">function</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE><A HREF="#prod9">literal</A></TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod13">var</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;VAR&gt; | &lt;UNNAMEDVAR&gt; ) ( <A HREF="#prod18">list</A> )?</TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod19">string</A></TD>
<TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
<TD ALIGN=LEFT VALIGN=BASELINE>&lt;STRING&gt;</TD>
</TR>
</TABLE>
</BODY>
</HTML>
